﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AgriculturalMachinery.Models
{
    public class ProductRepository : AgriculturalMachinery.Models.IProductRepository
    {
        private AgriMachineDataContext amdc = new AgriMachineDataContext();

        public IQueryable<ProductInfo> FindAllProducts()
        {
            return amdc.ProductInfo;
        }

        public ProductInfo FindProductByID(int id)
        {
            return amdc.ProductInfo.SingleOrDefault(d => d.StorageID == id);
        }

        public void addProduct(ProductInfo p)
        {
            amdc.ProductInfo.InsertOnSubmit(p);
            amdc.SubmitChanges();
        }

        public void deleteProduct(int id)
        {
            amdc.ProductInfo.DeleteAllOnSubmit(from i in amdc.ProductInfo
                                                   where i.StorageID == id
                                                   select i);
            amdc.SubmitChanges();
        }
    }
}
